/*
 *所有关于tb_project_reviewstandar_score类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*tb_project_reviewstandar_scoreService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using MYData.Core.BaseProvider;
using MYData.Core.Extensions.AutofacManager;
using MYData.Entity.DomainModels;
using System.Linq;
using MYData.Core.Utilities;
using System.Linq.Expressions;
using MYData.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using MYData.System.IRepositories;
using System.Net;
using MYData.Core.EFDbContext;
using Mapster;
using MYData.Entity.DomainModels.ApiEntity.Dto;

namespace MYData.System.Services
{
    public partial class tb_project_reviewstandar_scoreService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly Itb_project_reviewstandar_scoreRepository _repository;//访问数据库
        public readonly VOLContext _db;

        [ActivatorUtilitiesConstructor]
        public tb_project_reviewstandar_scoreService(
            Itb_project_reviewstandar_scoreRepository dbRepository,
            IHttpContextAccessor httpContextAccessor,
            VOLContext db
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            _db = db; 
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }

        WebResponseContent webResponse = new WebResponseContent();
        /// <summary>
        /// 标准分数添加
        /// </summary>
        /// <param name="inputdto"></param>
        /// <returns></returns>
        public WebResponseContent InsertWorkflowstep(tb_project_reviewstandar_scoreDto inputdto)
        {
            _db.Database.BeginTransaction();
            try
            {
                // 将输入Dto转换为领域模型
                var model = inputdto.Adapt<tb_project_reviewstandar_score>();
                // 添加基本信息到数据库
                _db.Set<tb_project_reviewstandar_score>().Add(model);
                if (_db.SaveChanges() < 1)
                {
                    _db.Database.RollbackTransaction();
                    return webResponse.Error("标准表分数添加失败！！！");
                }
                //提交事务
                _db.Database.CommitTransaction();
                //保存更改并返回
                return webResponse.OK("添加成功!", true);
            }
            catch (global::System.Exception)
            {
                _db.Database.RollbackTransaction();
                return webResponse.Error("添加失败！！！");

            }

        }
    }
}
